package cn.melonlib.cores.commons.comp.utils;

import cn.melonlib.cores.commons.model.entity.IEntity;
import cn.melonlib.cores.jpa.model.bean.collections.JsonMap;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component
public class EntityWrapperContainer {
    public static final String JSON = "json";
    public static final String FORM = "form";

    private JsonMap<IEntityWrapper> wraMap = new JsonMap<>();

    public <ENTITY extends IEntity<? extends Serializable>> ENTITY wrap(String name, String datas,
                                                                        Class<ENTITY> entityClass) throws Exception {
        return this.wraMap.get(name).wrap(datas, entityClass);
    }

    public EntityWrapperContainer addWrap(String name, IEntityWrapper wrapper) {
        this.wraMap.append(name, wrapper);
        return this;
    }
}
